package cn.kgc.jdbc.dao;

import cn.kgc.jdbc.entity.Course;
import cn.kgc.jdbc.utils.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author: mosin
 * @version: v1.0  2022/4/22
 */
public class CourseDaoImpl implements CourseDao {

    @Override
    public Course selectByName(String courseName) {

        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        String sql = "select id ,course_name as courseName from course  where course_name = ? ";
        try {
            Course course = queryRunner.query(sql, new BeanHandler<>(Course.class),courseName);
            return  course;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
